package com.thoughtworks.collection;

import sun.reflect.generics.reflectiveObjects.NotImplementedException;

import java.util.*;


public class MyMap {

    List<Integer> array;
    private String[] letters = new String[]{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l",
            "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
    private List<String> letterList = Arrays.asList(letters);

    public MyMap(List<Integer> array) {
        this.array = array;
    }

    public List<Integer> getTriple() {
        Map map=new HashMap();
        List list=new ArrayList();
        for (int i=0;i<array.size();i++){
            map.put(array.get(i),array.get(i)*3);
        }
        for (int i=0;i<array.size();i++){
            list.add(map.get(array.get(i)));
        }
        return list;
    }

    public List<String> mapLetter() {
        Map map=new HashMap();
        List list=new ArrayList();
        for (int i=0;i<letters.length;i++){
            map.put(i+1,letters[i]);
        }
        for (Integer s:array){
            list.add(map.get(s));
        }
        return list;
    }

    public List<String> mapLetters() {
        Map<Integer,String> map=new HashMap();
        List<String> list=new ArrayList();
        for (int i=0;i<letters.length;i++){
            map.put(i+1,letters[i]);
        }
        for (Integer s:array){
            if (s>26 && s%26!=0){
                list.add(map.get(s/26) + map.get(s % 26));
            }else if (s>26 && s%26==0){
                list.add(map.get(s/26-1)+"z");
            }
            else{
                list.add(map.get(s));
            }
        }

        return list;
    }

    public List<Integer> sortFromBig() {
        List<Integer> list=new ArrayList<>();
        int temp;
        Integer[] arr=new Integer[array.size()];
        array.toArray(arr);
        for(int i=0;i<arr.length-1;i++){//冒泡趟数
            for(int j=0;j<arr.length-i-1;j++){
                if(arr[j+1]>arr[j]){
                    temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                }
            }
        }
        list=Arrays.asList(arr);
        return list;
    }

    public List<Integer> sortFromSmall() {
        List<Integer> list=new ArrayList<>();
        int temp;
        Integer[] arr=new Integer[array.size()];
        array.toArray(arr);
        for(int i=0;i<arr.length-1;i++){//冒泡趟数
            for(int j=0;j<arr.length-i-1;j++){
                if(arr[j+1]<arr[j]){
                    temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                }
            }
        }
        list=Arrays.asList(arr);
        return list;
    }
}
